package com.kennedy.atoupdate.web.controller;

import com.github.pagehelper.PageInfo;
import com.kennedy.atoupdate.beans.DeviceInfo;
import com.kennedy.atoupdate.beans.VersionInfo;
import com.kennedy.atoupdate.beans.common.ResultMsg;
import com.kennedy.atoupdate.beans.dto.UpdateGroupRequest;
import com.kennedy.atoupdate.service.DeviceInfoService;
import com.kennedy.atoupdate.service.VersionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by tao.zeng on 2017/8/15.
 */
@Controller
@RequestMapping("deviceInfo")
public class DeviceInfoController {
    @Autowired
    private DeviceInfoService deviceInfoService;

    @GetMapping("/toList")
    public String toLogin() {
        return "deviceinfo/list";
    }

    @GetMapping("/getListByPage")
    @ResponseBody
    public PageInfo<DeviceInfo> getListByPage(DeviceInfo deviceInfo) {
        List<DeviceInfo> deviceInfos = deviceInfoService.getListByPage(deviceInfo);
        return new PageInfo<DeviceInfo>(deviceInfos);
    }

    @DeleteMapping("/delete/{id}")
    @ResponseBody
    public ResultMsg delete(@PathVariable("id") Long id) {
        try {
            deviceInfoService.delete(id);
        } catch (Exception e) {
            return ResultMsg.error();
        }
        return ResultMsg.success();
    }

    @PostMapping("/updateGroup")
    @ResponseBody
    public ResultMsg updateGroup(@RequestBody UpdateGroupRequest updateGroupRequest) {
        try {
            deviceInfoService.updateGroup(updateGroupRequest);
        } catch (Exception e) {
            return ResultMsg.error();
        }
        return ResultMsg.success();
    }

}
